//
//  HYGameInfoServerCell.m
//  HaiYue
//
//  Created by skyline on 2018/5/16.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYGameInfoServerCell.h"
#import "HYGameDetailModel.h"
#import "HYFillLabel.h"
@interface  HYGameInfoServerCell ()
@property (nonatomic, strong) HYLabel *label;
@end
@implementation HYGameInfoServerCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
- (void)setServerlist:(NSMutableArray<HYGameDetailServerModel *> *)serverlist
{
    if (_serverlist != serverlist)
    {
        _serverlist = serverlist;
        self.label.hidden = [_serverlist count] < 1 ?NO:YES;
        [self setupSubView];
    }
}
- (HYLabel *)label
{
    if (!_label)
    {
        _label = [[HYLabel alloc] initWithText:@"亲，该游戏暂无开服信息哦~~" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TitleFont]];
        [self addSubview:_label];
        [_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
        }];
    }
    return _label;
}

- (void)setupSubView
{
    for (int i = 0 ; i < self.serverlist.count; i++)
    {
        int row = ceil(i / 2);//行
        int coloum = i % 2;//列
        
        HYGameDetailServerModel *model = self.serverlist[i];
        HYFillLabel *lbl = [[HYFillLabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH / 2.0 - 1.5 * GAP, 25)
                                            typeOfshapeLayer:CCShapeLayerTypeEllipse
                                                   attribute:@{HYTextColor:[UIColor whiteColor],HYTextFont:[UIFont systemFontOfSize:12],HYBorderColor:THEME_COLOR}];
        lbl.text = [NSString stringWithFormat:@"%@ %@",model.name, [model.date substringWithRange:NSMakeRange(5, 11)]];
        [self addSubview:lbl];
        [lbl mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(GAP + row * (25 + GAP));
            make.left.equalTo(self).with.offset(GAP + coloum * (lbl.bounds.size.width + GAP));
            make.size.mas_equalTo(lbl.bounds.size);
        }];
    }
    
}
@end
